class Solution(object):
    def lexicalOrder(self, n):
        """
        :type n: int
        :rtype: List[int]
        """
        ret = []
        def fun(acc):
            if acc>n: return False
            ret.append(acc)
            for i in range(10): 
                if not fun(acc*10+i): break
            return True
        for i in range(1, 10): fun(i)
        return ret

print(Solution().lexicalOrder(23489))